import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);
// 这是Vue-Router的配置文件了，核心配置就是这个routes变量
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
};

/**
 * @type {import("vue-router").RouteConfig[]}
 */
const routes = [
  {
    path: "/admin",
    component: require("@/views/admin/").default,
    children: [
      {
        path: "/admin/p1",
        component: require("@/views/admin/AdminPage1").default,
      },
      {
        path: "/admin/p2",
        component: require("@/views/admin/AdminPage2").default,
      },
    ],
  },
  {
    path: "/",
    component: require("@/views/common").default,
    meta: {
      isTurn: true,
      authorInfo: true,
    },
    children: [
      {
        path: "/userInfo",
        component: require("@/views/common/userInfo").default,
        meta: {
          isTurn: false,
          authorInfo: false,
        },
      },
      {
        path: "/type",
        component: require("@/views/common/type").default,
        meta: {
          isTurn: false,
        },
      },
      {
        path: "/search",
        component: require("@/views/common/search").default,
        meta: {
          isTurn: false,
        },
      },
      {
        path: "/manager",
        component: require("@/views/common/contentManage").default,
        meta: {
          isTurn: false,
        },
      },
      {
        path: "/editor",
        component: require("@/views/common/editArticle").default,
        meta: {
          isTurn: false,
        },
      },
      {
        path: "/articleDetail",
        component: require("@/views/common/articleDetail").default,
        meta: {
          isTurn: false,
        },
      },
      {
        path: "/otherUser",
        component: require("@/views/common/otherUserInfo").default,
        meta: {
          isTurn: false,
        },
      },
    ],
  },
  {
    path: "/login",
    component: require("@/views/common/login").default,
    meta: {
      isTurn: true,
    },
  },
  {
    path: "/register",
    component: require("@/views/common/register").default,
  },
];

const router = new VueRouter({
  routes,
});

export default router;
